#include <stdio.h>
#include "ofc/DTextWritableLogger.h"
#include "ofc/DLog.h"
#include "ofc/DFile.h"

int main(int argc, char *argv[])
{
  DTextWritableLogger *logger = [DTextWritableLogger new];
  DFile               *file   = [DFile new];
  char                 name[] = "example.log";
  int                  i;

  if ([file open :name :"w"])
  {
    [logger writer :file];             // Give to the textwriteable logger the destination file

    dlogger(logger);                   // Give to the base logger the textwritable logger as destination

    dlog(DLOG_ALERT, "Alert!!");       // Log an alert

    for (i = 0; i < 10; i++)           // Add a repeated error message
    {
      dlog(DLOG_ERROR, "Errors");
    }

    dlogmask(DLOG_NOTICE|DLOG_DEBUG);  // Mask some log levels
    
    dlog(DLOG_WARNING, "Warning..masked"); // Masked warning
    dlog(DLOG_DEBUG,   "Debug:%d",7);  // Debug message
    dlog(DLOG_NOTICE,  "Notice.");     // Notice message

    dlogger(nil);                      // Stop logging via the textwritable logger

    [file close];                      // Close the destination file

    printf("Events succesfully logged in \"%s\".\n", name);
  }
  else
    printf("Could not open \"%s\" for writing:%d.\n", name, [file error]);

  [logger free];                       // Cleanup
  [file   free];

  return 0;
}

